package com.cq.androidtools.反射

/**
 * 作者: CQ
 * 日期: 2021-08-24
 * 说明:
 */

fun main() {
    val a = ClassA()
    val classs = a.javaClass.superclass.superclass
    val name = classs.getDeclaredField("name")
    name.isAccessible = true
    name.set(a, "ClassA")

    val printaa = classs.getMethod("printaa")
    printaa.invoke(a)

    print(a.toString())
}

class ClassA : ClassB() {}

open class ClassB : ClassC() {}

open class ClassC {
    protected val name = "ClassC"
    override fun toString(): String {
        return "ClassC(name='$name')"
    }

    fun printaa(){
        print("name")
    }

}